package com.baseproject.bottomnavigation;

import android.app.Activity;
import android.graphics.Color;

import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
import com.baseproject.R;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by hp on 2017/9/3.
 */

public class AHBottomNavigationHelper {

    AHBottomNavigation bottomNavigation;
    private ArrayList<AHBottomNavigationItem> bottomNavigationItems = new ArrayList<>();

    public AHBottomNavigationHelper initView(Activity activity, BottomNavigationModel bottomNavigationModel, AHBottomNavigation.OnTabSelectedListener onTabSelectedListener) {
        bottomNavigation = (AHBottomNavigation) activity.findViewById(bottomNavigationModel.getBottomNavigationRid());
        Map<Integer, Integer> bottomNavigationMap = bottomNavigationModel.getBottomNavigationMap();
        Set<Integer> keySet = bottomNavigationMap.keySet();
        Iterator iterrator = keySet.iterator();
        while (iterrator.hasNext()) {
            Integer key = (Integer) iterrator.next();
            AHBottomNavigationItem item = new AHBottomNavigationItem(key, bottomNavigationMap.get(key), R.color.colorBottomNavigationActiveColored);
            bottomNavigationItems.add(item);
        }

        bottomNavigation.addItems(bottomNavigationItems);
        bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FFFFFF"));
        bottomNavigation.setBehaviorTranslationEnabled(false);
        bottomNavigation.setAccentColor(activity.getResources().getColor(bottomNavigationModel.getButtomSelectedColor()));
        bottomNavigation.setInactiveColor(activity.getResources().getColor(bottomNavigationModel.getButtomUnSelectedColor()));
        bottomNavigation.setForceTint(true);
        bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
        bottomNavigation.setTitleTextSizeInSp(13, 11);
        bottomNavigation.setCurrentItem(0);

        bottomNavigation.setOnTabSelectedListener(onTabSelectedListener);
        return this;
    }

    public AHBottomNavigation getBottomNavigation() {
        return bottomNavigation;
    }
}
